//
//  ReNewAlbumLayout.m
//  MusicPlayer
//
//  Created by dlios on 15-5-25.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "ReNewAlbumLayout.h"

@implementation ReNewAlbumLayout
- (void)dealloc
{
    [super dealloc];
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

#pragma mark - 获得并设置每个cell的布局方式
- (void)prepareLayout
{
    [super prepareLayout];
    self.attributeArray = [NSMutableArray array];
    // 获得有多少个item
    NSInteger itemNum = [self.collectionView numberOfItemsInSection:0];
    // 10个item，第一个item大小
    for (int i = 0; i < itemNum; i++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
        
        // 获得第几个item的属性
        UICollectionViewLayoutAttributes *att = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
        att.frame = CGRectMake(i % 2 * self.collectionView.frame.size.width / 375 * 170 + self.collectionView.frame.size.width / 375 * 20, self.collectionView.frame.size.width / 375 *  i / 2 * self.collectionView.frame.size.width / 375 * 192 + self.collectionView.frame.size.width / 375 * 30, self.collectionView.frame.size.width / 375 * 160, self.collectionView.frame.size.width / 375 * 160);
        [self.attributeArray addObject:att];
    }
}

#pragma mark - 将cell的属性赋值给cell

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
    // 将显示的cell的属性取出，并返回
    NSMutableArray *array = [NSMutableArray array];
    for (UICollectionViewLayoutAttributes *layout in self.attributeArray) {
        [array addObject:layout];
    }
    return array;
}

@end
